<template>
    <el-container class="activityBox">
        <el-main class="mainBox">
            <div class="activityContent">
                <div class="title">
                    <label>教研活动</label>
                </div>

                <el-form :inline="true" class="demo-form-inline">
                    <el-form-item label="主题：" style="margin-right: 22px;">
                        <el-select size="small" v-model="theme" placeholder="请选择主题">
                            <el-option label="主题类型" value="0"></el-option>
                            <el-option label="主题研讨" value="100"></el-option>
                            <el-option label="课例研讨" value="101"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="状态：">
                        <el-select size="small" v-model="state" placeholder="请选择主题">
                             <el-option label="活动状态" value="0"></el-option>
                            <el-option label="未开始" value="100"></el-option>
                            <el-option label="正在进行中" value="101"></el-option>
                            <el-option label="已结束" value="102"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>

                <el-row :gutter="20" v-if="activityPageListP">
                    <el-col :span="6" v-for="(item, index) in activityPageListP.list" :key="index">
                        <div class="grid-content" @click="toResearchReadDetails(item,3)">
                            <div class="cover">
                                <el-image :src="item.cover | pictureUrl" style="height: 200px;"></el-image>
                            </div>

                            <div class="heading">
                                <label>[ 主题研讨 ] {{item.title}}</label>
                            </div>

                            <div class="stateWarp">
                                <label class="state">
                                    状态：{{item.state}}
                                </label>
                                <label class="browse">
                                    浏览：{{item.viewnum}}
                                </label>
                            </div>
                        </div>
                    </el-col>
                </el-row>

                <div class="block">
                    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="page" :page-sizes="[8, 12, 16, 20]" :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper" :total="total">
                    </el-pagination>
                </div>
            </div>
        </el-main>
        <el-aside class="rightBox">
            <div class="activityContent">
                <div class="title">
                    <label>热门活动</label>
                </div>
                <ul class="hotWarp">
                    <li class="hotList" v-for="(item, index) in activityHotPageListP.list" :key="index"
                    @click="toResearchReadDetails(item,3)">
                        <div class="user">
                            <span>{{index+1}}</span>
                            <label>{{item.title}}</label>
                        </div>
                    </li>
                </ul>
            </div>
        </el-aside>
    </el-container>
</template>

<script>
    import {mapState} from 'vuex'
    export default {
        computed:{
            ...mapState({
                userInfo: state => state.userModule.userInfo,
                otherUserInfo: state => state.userModule.otherUserInfo,
            })
        },
        watch:{
            theme(val){
                this.activityPageList(val)
            },
            state(val){
                this.activityPageList(this.theme)
            }
        },
        created(){
            this.activityPageList(0)
            this.activityHotPageList(0)
        },
        data() {
            return {
                theme:'0',
                state:'0',
                src: require('../../../assets/img/headportrait01.jpg'),
                page: 1,
                pageSize: 8,
                total: 0,
                activityPageListP:{},
                activityHotPageListP:{}
            }
        },
        methods: {
            toResearchReadDetails(params,type){
                if (this.userInfo.id && this.otherUserInfo.userid && 
                this.userInfo.id != this.otherUserInfo.userid) {
                    this.$store.dispatch('visitorAllModule/visitorAdd', {
                        fromuserid: this.otherUserInfo.userid,
                        visitorid: params.id,
                        type: type == 3?6:2
                    })
                }
                this.$router.push({path:'/research/researchOther/researchReadDetails',query:{
                    routePath: 'researchOtherActivity',
                    article: params,
                    junmpType: type}})
            },
            activityHotPageList(params){
                this.$store.dispatch('researchModule/hotActivity', {
                    organizationId: this.otherUserInfo.xxdm,
                }).then(res =>{
                    if(res){
                        this.activityHotPageListP =res 
                    }
                })
            },
            activityPageList(params){
                this.$store.dispatch('researchModule/activityPage', {
                    dictype: params,
                    groupId:null,
                    state: this.state,
                    organizationId: this.otherUserInfo.xxdm,
                    limit: this.pageSize,
                    page: this.page,
                }).then(res =>{
                    if(res){
                        this.total = res.total
                        this.activityPageListP =res 
                    }
                })
            },
            // 每页显示条数
            handleSizeChange(val) {
                this.pageSize = val
                this.activityPageList()
            },

            // 当前页
            handleCurrentChange(val) {
                this.page = val
                this.activityPageList()
            }
        },
    }
</script>

<style lang="scss" scoped>
    .activityBox {
        width: 81%;
        margin: 0 auto;

        .title {
            font-size: 14px;
            color: #303133;
            text-align: left;
            box-sizing: border-box;
            padding-bottom: 8px;
            border-bottom: 2px solid #409EFF;

        }

        .activityContent {
            background-color: white;
            box-sizing: border-box;
            padding: 10px;
            width: 100%;
            height: 100%;
        }

        .mainBox {
            padding-left: 0;

            .demo-form-inline {
                text-align: left;
                margin-top: 22px;
            }

            .grid-content {
                background-color: #F2F6FC;
                margin-bottom: 22px;

                .cover {
                    width: 100%;
                }

                .heading {
                    box-sizing: border-box;
                    padding: 0 10px;
                    width: 100%;
                    height: 30px;
                    line-height: 30px;
                    font-size: 14px;
                    color: #303133;
                    text-align: left;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    text-align: left;
                }

                .stateWarp {
                    box-sizing: border-box;
                    padding: 0 10px;
                    width: 100%;
                    line-height: 30px;
                    display: flex;
                    justify-content: space-between;
                    flex-wrap: wrap;
                    font-size: 14px;

                    .state {
                        color: #303133;
                    }

                    .browse {
                        color: #909399;
                    }
                }
            }
        }

        .rightBox {
            padding: 20px 0;

            .hotWarp {
                list-style-type: none;
                margin-block-start: 0;
                margin-block-end: 0;
                padding-inline-start: 0;
                margin-top: 10px;

                .hotList {
                    height: 40px;
                    line-height: 40px;

                    .user {
                        float: left;
                        color: #303133;
                        font-size: 14px;
                        width: 100%;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                        text-align: left;

                        span {
                            display: inline-block;
                            width: 20px;
                            height: 20px;
                            line-height: 20px;
                            color: white;
                            text-align: center;
                            background-color: #909399;
                            margin-right: 6px;
                        }
                    }
                }

                .hotList:nth-child(1) .user>span,
                .hotList:nth-child(2) .user>span,
                .hotList:nth-child(3) .user>span {
                    background-color: #409EFF;
                }
            }
        }
    }
</style>